﻿Shader "Level4/FX/SimpleFlag" {
	Properties {
		_MainTex ("Base (RGB)", 2D) = "white" {}
		_WaveStrength("Wave Strength",float) = 1
		_WaveSpeed("Wave Speed",float) = 1
	}
	
	CGINCLUDE
	#include "UnityCG.cginc"
	sampler2D _MainTex;
	float _WaveStrength;
	float _WaveSpeed;
	
	struct v2f{
		float4 pos:POSITION;
		float2 uv:TEXCOORD;
	};
	
	void ComputeWave(inout appdata_base i,inout v2f o){
		float sinOff = (i.vertex.x + i.vertex.y + i.vertex.z) * _WaveStrength;
		float t = -_Time * _WaveSpeed;
		float fx = i.texcoord.x;
		float fy = i.texcoord.x * i.texcoord.y;
		
		i.vertex.x += sin(t * 1.45 + sinOff) * fx * 0.5;
		i.vertex.y = (sin(t * 3.12 + sinOff) * fx * 0.5 - fy * 0.9);
		i.vertex.z -= (sin(t * 2.2 + sinOff) * fx * 0.2);
		
		o.pos = mul(UNITY_MATRIX_MVP,i.vertex);
		o.uv = i.texcoord;
	}
	
	v2f vert(appdata_base i){
		v2f o;
		ComputeWave(i,o);
		return o;
	}
	
	float4 frag(v2f i):COLOR{
		float4 c = tex2D(_MainTex,i.uv);
		return c;
	}
	

	
	ENDCG
	
	SubShader {
		Tags { "RenderType"="Opaque" }
		LOD 200
		Blend SrcAlpha OneMinusSrcAlpha
		
		Pass{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			ENDCG
		}
	} 
	FallBack "Diffuse"
}
